import * as cart from '@/api/cart.js';
const state = {};
const mutations = {};
const getters = {};
const actions = {
	//添加商品到购物车
	cartAdd({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartAdd(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//订单提交前的检验和填写相关订单信息
	cartCheckOut({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartCheckOut(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//删除某个购物车商品
	cartDel({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartDel(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//获取购物车中的数据
	getCart({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.getCart(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//获取购物车商品的总件件数
	cartGoodsCount({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartGoodsCount(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//获取购物车信息
	cartIndex({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartIndex(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//减少商品到购物车
	cartMinus({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartMinus(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//更新指定的购物车信息
	cartUpdate({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartUpdate(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//清空购物车
	cartCLear({ commit }, payload = {}) {
		return new Promise((resolve, reject) => {
			cart.cartCLear(payload).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	}
};

export default { state, getters, mutations, actions };
